#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
//package org.jeecg.modules.online.desform.test;
//
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import lombok.extern.slf4j.Slf4j;
//import org.jeecg.JeecgSystemApplication;
//import org.jeecg.common.util.oConvertUtils;
//import org.jeecg.modules.online.desform.entity.DesignForm;
//import org.jeecg.modules.online.desform.entity.DesignFormAuth;
//import org.jeecg.modules.online.desform.service.IDesignFormAuthService;
//import org.jeecg.modules.online.desform.service.IDesignFormService;
//import org.jeecg.modules.online.desform.util.DesformUtils;
//import org.jeecg.modules.online.desform.vo.excel.DesformWidgetList;
//import org.jeecg.modules.online.desform.vo.widget.DesformWidget;
//import org.junit.jupiter.api.Test;
//import org.junit.runner.RunWith;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.test.context.junit4.SpringRunner;
//
//import java.util.Arrays;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
///**
// * 表单设计器更新权限值类型
// */
//@Slf4j
//@RunWith(SpringRunner.class)
//@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = JeecgSystemApplication.class)
//public class UpdateAuthValueType {
//
//    @Autowired
//    IDesignFormService designFormService;
//    @Autowired
//    IDesignFormAuthService designFormAuthService;
//
//    Map<String, DesformWidgetList> widgetListMap = new HashMap<>();
//
//    @Test
//    public void updateAuthValueType() {
//        // 查询出所有的表单设计器
//        List<DesignForm> designFormList = designFormService.list();
//        log.info("已查询出所有的表单设计器，共{}条${symbol_escape}n", designFormList.size());
//        for (DesignForm designForm : designFormList) {
//            String desformCode = designForm.getDesformCode();
//            // 查询出该表单下的所有权限
//            LambdaQueryWrapper<DesignFormAuth> authWrapper = new LambdaQueryWrapper<>();
//            authWrapper.eq(DesignFormAuth::getDesformCode, desformCode);
//            // 只有数据权限才需要更新
//            authWrapper.eq(DesignFormAuth::getPermissionType, "data");
//            List<DesignFormAuth> auths = designFormAuthService.list(authWrapper);
//            if (auths.isEmpty()) {
//                continue;
//            }
//            log.info("正在更新：{}，该表单共有{}条数据权限", desformCode, auths.size());
//            // 获取权限值类型
//            for (DesignFormAuth auth : auths) {
//                String authValueType = auth.getAuthValueType();
//                // 已经获取过的，不重复获取
//                if (oConvertUtils.isNotEmpty(authValueType)) {
//                    continue;
//                }
//                // 获取控件列表
//                DesformWidgetList widgetList = widgetListMap.get(desformCode);
//                if (widgetList == null) {
//                    widgetList = DesformUtils.getDesformWidgetListByEntity(designForm);
//                    widgetListMap.put(desformCode, widgetList);
//                }
//                // 判断是否是子表
//                String valueType = null;
//                if (auth.getSubTable() != null && auth.getSubTable()) {
//                    List<DesformWidget> widgets = widgetList.sub.get(auth.getSubKey());
//                    if (widgets == null) {
//                        widgets = widgetList.subOne.get(auth.getSubKey());
//                    }
//                    if (widgets == null) {
//                        log.error("子表控件不存在，可能被删除，表单：{}，子表：{}", desformCode, auth.getSubKey());
//                        continue;
//                    }
//                    valueType = this.getAuthValueType(widgets, auth.getAuthField());
//                } else {
//                    valueType = this.getAuthValueType(widgetList.main, auth.getAuthField());
//                }
//                if (oConvertUtils.isEmpty(valueType)) {
//                    valueType = "string";
//                }
//                DesignFormAuth newAuth = new DesignFormAuth();
//                newAuth.setId(auth.getId());
//                newAuth.setAuthValueType(valueType);
//                designFormAuthService.updateById(newAuth);
//                log.info("--- 已更新权限值类型，表单：{}，字段：{}，值类型：{}", desformCode, auth.getAuthField(), valueType);
//            }
//            log.info("更新完成。${symbol_escape}n");
//        }
//    }
//
//    // 存储为数字类型的字段
//    List<String> numberFields = Arrays.asList("number", "integer", "money", "rate", "slider");
//
//    String getAuthValueType(List<DesformWidget> widgetList, String model) {
//        for (DesformWidget widget : widgetList) {
//            if (model.equals(widget.getModel())) {
//                String type = widget.getType().getType();
//                if (numberFields.contains(type)) {
//                    return "number";
//                } else {
//                    return type;
//                }
//            }
//        }
//        return "string";
//    }
//
//}
